import { httpMI } from '@/utils/requestMI'
import type { ICartList, IOrderList, IOrderInfo, IPayInfo } from '@/types/cart'

/**
 * @description 获取购物车列表
 * @returns Promise
 */
export const reqCartList = () => {
  return httpMI<ICartList[]>('/api/cart/cartList', 'GET')
}

/**
 * @description 切换商品选中状态
 * @param {*} id 商品的id
 * @param {*} isChecked 商品的最新状态
 * @returns
 */
export const reqCheckCart = (id:number, isChecked:number) => {
  return httpMI(`/api/cart/checkCart/${id}/${isChecked}`, 'GET')
}

/**
 * @description 购物车商品全选
 * @param {*} isChecked 商品的最新状态
 * @returns
 */
export const reqBatchCheckCart = (isChecked: number, skuIdList:number[]) => {
  return httpMI(`/api/cart/batchCheckCart/${isChecked}`, 'POST', skuIdList)
}

/**
 * @description 改变购物车数量
 */
export const reqUpdateNum = (skuId: string, skuNum: string) => {
  return httpMI(`/api/cart/addToCart/${skuId}/${skuNum}`, 'POST')
}

/**
 * @description 删除商品
 */
export const reqDelCart = (skuId: string) => {
  return httpMI(`/api/cart/deleteCart/${skuId}`, 'DELETE')
}

/**
 * @description 获取交易页面的信息
 * @returns Promise
 */
export const reqTradeInfo = () => {
  return httpMI<IOrderInfo>('/api/order/auth/trade', 'GET')
}

/**
 * @description 提交订单
 * @returns
 */
export const reqSubmitOrder = (data: IOrderList) => {
  return httpMI(`/api/order/auth/submitOrder?tradeNo=${data.tradeNo}`, 'POST', data)
}

/**
 * @description 获取订单支付信息
 * @returns
 */
export const reqPayInfo = (id: string) => {
  return httpMI<IPayInfo>(`/api/payment/weixin/createNative/${id}`, 'GET')
}

/**
 * @description 获取订单支付状态
 * @returns
 */
export const reqPayStatus = (id: string) => {
  return httpMI(`/api/payment/weixin/queryPayStatus/${id}`, 'GET')
}